package pumpeddevs.game.wishbone;

import pumpeddevs.game.framework.PDActivity;
import pumpeddevs.game.wishbone.sprites.LoadingPage;
import pumpeddevs.game.wishbone.stage1.Stage1;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Point;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends PDActivity {
	
	private static int _width;
	private static int _height;
	private static LoadingPage _loadingPage;
	private static MainActivity instance;
	
	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
		instance = this;

		Display display = getWindowManager().getDefaultDisplay();
		Point size = new Point();
		
		try {
			display.getSize(size);
			MainActivity._width = size.x;
			MainActivity._height = size.y;
		}catch(NoSuchMethodError e){
			MainActivity._width = display.getWidth();
			MainActivity._height = display.getHeight();
		}
		
		MainActivity._loadingPage = new LoadingPage(this, MainActivity._width, MainActivity._height,10);
		setContentView(MainActivity._loadingPage);
		
		
//		for(int i = 0; i <= 10; i++) {
//				MainActivity._loadingPage.incrementProgressBar();
//		}
		
		
	}	

	public static void nextStage() {
		MainActivity._loadingPage.stop();
		Stage1 stage1 = new Stage1(MainActivity.instance, MainActivity._width, MainActivity._height);
		MainActivity.instance.setContentView(stage1);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	/**
	 * A placeholder fragment containing a simple view.
	 */
	public static class PlaceholderFragment extends Fragment {

		public PlaceholderFragment() {
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_main, container,
					false);
			return rootView;
		}
	}

	@Override
	public void onBackPressed() {
		this._loadingPage.stop();
		super.onBackPressed();
	}
}
